package com.zx.lc.demo;

import dev.langchain4j.model.chat.response.ChatResponse;
import dev.langchain4j.model.chat.response.StreamingChatResponseHandler;
import dev.langchain4j.model.ollama.OllamaStreamingChatModel;
import java.io.IOException;
import java.util.concurrent.locks.LockSupport;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class C3响应式 {

    public static void main(String[] args) throws IOException {
        OllamaStreamingChatModel model = OllamaStreamingChatModel.builder()
                .baseUrl("http://192.168.3.99:11434")
                .modelName("qwen2.5:7b")
                .build();

        Thread thread = Thread.currentThread();

        model.chat("你好，帮我查下鱼香肉丝怎么做？", new StreamingChatResponseHandler() {

            @Override
            public void onPartialResponse(String partialResponse) {
                System.out.print(partialResponse);
            }

            @Override
            public void onCompleteResponse(ChatResponse completeResponse) {
                System.out.println("ok");
                LockSupport.unpark(thread);
            }

            @Override
            public void onError(Throwable error) {
                System.out.println(error);
            }
        });

        LockSupport.park();
    }

}
